//
//  PanoramaBrowserViewController.swift
//  Kool Car
//
//  Created by huangweiqiang on 2022/3/2.
//

import UIKit
import GLKit

class PanoramaBrowserViewController: GLKViewController {
    var panoramaView: PanoramaView!
    var vrImage: UIImage!
    var backBtn: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        panoramaView = PanoramaView.init(frame: CGRect.init(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight))
        panoramaView?.orientToDevice = false
        panoramaView?.touchToPan = true
        panoramaView?.pinchToZoom = true
        panoramaView?.showTouches = false
        panoramaView?.vrMode = false
//        panoramaView?.setImageWithName("andes.jpg")
        panoramaView.setImage(vrImage)
        self.view = panoramaView
        
        backBtn = UIButton.init(frame: CGRect.init(x: 0, y: IphoneTopArea, width: 50, height: 44))
        backBtn.setImage(UIImage.init(named: "icon_navi_back_white"), for: .normal)
        backBtn.setImage(UIImage.init(named: "icon_navi_back_white"), for: .highlighted)
        backBtn.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside)
        self.navigationController?.view.addSubview(backBtn)
        
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    }
    
    @objc func backBtnAction(){
        if self.backBtn != nil {
            self.backBtn.removeFromSuperview()
        }
        self.navigationController?.popViewController(animated: true)
    }
    
    override func glkView(_ view: GLKView, drawIn rect: CGRect) {
        self.panoramaView.draw()
    }
}
